<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('统计列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <input id="treeId" name="deptId" type="hidden"/>
                <input id="categoryTreeId" name="thingId" type="hidden"/>
                <input id="thingTypeId" name="thingTypeId" type="hidden"/>
                <div class="select-list">
                    <ul>
                        <li>
                            <label>行名称：</label>
                            <input readonly="readonly" onclick="selectDeptTree()" id="treeName" type="text"
                                   placeholder="请选择归属行">
                        </li>
                        <li>
                            <label>物品目录：</label>
                            <input readonly="readonly" onclick="selectCategoryTree()" id="categoryTreeName" type="text"
                                   placeholder="请选择物品分类">
                        </li>
                        <li>
                            <label>收支项目：</label>
                            <input readonly="readonly" onclick="selectThingTypeTree()" id="thingType" type="text"
                                   placeholder="请选择收支项目">
                        </li>
                        <li>
                            <label style="width: 150px">单价（发票信息）：</label>
                            <input type="text" name="fdanjia" style="width: 70px"/>
                        </li>
                        <li>
                            <label style="width: 150px">数量（发票信息）：</label>
                            <input type="text" name="fshuliang" style="width: 70px"/>
                        </li>

                        <li>
                            <label style="width: 150px">物品单位（发票信息）：</label>
                            <input type="text" name="danwei" style="width: 70px"/>
                        </li>
                        <li>
                            <label>品牌：</label>
                            <input type="text" name="pinpai" style="width: 100px"/>
                        </li>
                        <li>
                            <label>型号：</label>
                            <input type="text" name="xinghao" style="width: 100px"/>
                        </li>
                        <li>
                            <label style="width: 150px">最小度量含税单价：</label>
                            <input type="text" name="danjia" style="width: 70px"/>
                        </li>
                        <li>
                            <label style="width: 150px">发票金额+税额：</label>
                            <input type="text" name="zonge" style="width: 70px"/>
                        </li>

                        <li class="select-time">
                            <label>入库时间： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginTime]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endTime]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="chongzhi()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="financial:tongji:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "financial/tongji";

    $(function () {
        var options = {
            url: prefix + "/tongjiEnterList",
            exportUrl: prefix + "/export",
            modalName: "统计列表",
            showFooter: true,
            footerStyle: footerStyle,
            pageSize: 100,
            pageList: [100],
            columns: [{
                checkbox: true
            },
                {
                    field: 'deptName',
                    title: '行名称'
                },
                {
                    field: 'sumShuliang',
                    title: '入库数量'
                },
                {
                    field: 'shengjunShuliang',
                    title: '全省机构平均数量'
                },
                {
                    field: 'pingjundanjia',
                    title: '平均单价'
                },
                {
                    field: 'shengjundanjia',
                    title: '全省机构平均单价'
                },
                {
                    field: 'renjunliang',
                    title: '人均用量'
                },
                {
                    field: 'shengrenjunliang',
                    title: '全省机构人均用量'
                },
                {
                    field: 'renjunZonge',
                    title: '人均支出金额'
                },
                {
                    field: 'shengrenjunZonge',
                    title: '全省机构人均支出金额'
                },
                {
                    field: 'minDanjia',
                    title: '最小含税单价'
                },
                {
                    field: 'maxDanjia',
                    title: '最高含税单价'
                },
                {
                    field: 'sumZonge',
                    title: '支出总额',
                    footerFormatter: function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            if (value[i].sumZonge) {
                                sumBalance += parseFloat(value[i].sumZonge);
                            }
                        }
                        return "" + sumBalance.toFixed(2);
                    }
                },
                {
                    field: 'xunizonge',
                    title: '非实物总额',
                    footerFormatter: function (value) {
                        var sumBalance = 0;
                        for (var i in value) {
                            if (value[i].xunizonge) {
                                sumBalance += parseFloat(value[i].xunizonge);
                            }
                        }
                        return "" + sumBalance.toFixed(2);
                    }
                }]
        };
        $.table.init(options);
    });

    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/user/selectDeptTree/" + deptId;
        var options = {
            title: '选择行',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function selectCategoryTree() {
        var treeId = $("#categoryTreeId").val();
        var url = ctx + "financial/fThing/selectFThingCategoryTree/";
        var options = {
            title: '选择物品',
            width: "380",
            url: url,
            callBack: doSubmit2
        };
        $.modal.openOptions(options);
    }

    function doSubmit2(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#categoryTreeId").val(body.find('#treeId').val());
        $("#categoryTreeName").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function selectThingTypeTree() {
        var treeId = $("#categoryTreeId").val();
        var url = ctx + "financial/thingType/selectThingTypeTree/";
        var options = {
            title: '选择收支项目',
            width: "380",
            url: url,
            callBack: doSubmit3
        };
        $.modal.openOptions(options);
    }

    function doSubmit3(index, layero) {
        var body = $.modal.getChildFrame(index);
        $("#thingTypeId").val(body.find('#treeId').val());
        $("#thingType").val(body.find('#treeName').val());
        $.modal.close(index);
    }

    function chongzhi() {
        $("#treeId").val("")
        $("#categoryTreeId").val("")
        $("#thingTypeId").val("")
        $.form.reset()
    }

    function footerStyle(column) {
        return {
            sumZonge: {
                css: {color: 'red', 'font-weight': 'normal'}
            },
            xunizonge: {
                css: {color: 'red', 'font-weight': 'normal'}
            }
        }[column.field]
    }

</script>
</body>
</html>